package com.lwl.controller.mht;

import com.github.pagehelper.PageInfo;
import com.lwl.entity.LayData;
import com.lwl.entity.MyPage;
import com.lwl.entity.mht.TMhtPlane;
import com.lwl.entity.Tuser;
import com.lwl.service.mht.TMhtPlaneService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * (TMhtPlane)表控制层
 *
 * @author Lei
 * @since 2022-10-27 16:57:40
 */
@RestController
@RequestMapping("tMhtPlane")
public class TMhtPlaneController {
    /**
     * 服务对象
     */
    @Autowired
    private TMhtPlaneService tMhtPlaneService;

    /**
     * 查询所有的测试计划
     * @return
     */
    @GetMapping("queryAll")
    public LayData queryAll(MyPage myPage, TMhtPlane tMhtPlane){
        PageInfo pageInfo = tMhtPlaneService.queryAll(myPage,tMhtPlane);
        return new LayData(pageInfo);
    }

    /**
     * 根据邀请码查询对应的测试计划，如果已经有对应的邀请码，那就需要生成一个新的邀请码
     * @param tMhtPlane
     * @return
     */
    @PostMapping("selectCode")
    public LayData selectCode(TMhtPlane tMhtPlane){
         boolean status = tMhtPlaneService.selectCode(tMhtPlane);
         return new LayData(status);
    }

    /**
     *  添加/修改 测试计划
     */
    @PostMapping("addPlane")
    public LayData insertplane(TMhtPlane tMhtPlane, HttpSession session){
        Tuser user = (Tuser)session.getAttribute("user");
        tMhtPlane.setCreatetime(new Date());
        tMhtPlane.setUid(user.getId());
        return new LayData(tMhtPlaneService.insertPlane(tMhtPlane));
    }

    /**
     * 计划唯一性校验
     */
    @PostMapping("queryByPlaneName")
    public LayData queryByName(String planname){
        return  new LayData(tMhtPlaneService.queryByName(planname));
    }

    /**
     * 用户登录做题时，根据邀请码查询测试计划的具体内容，用来判断是否在做题时间
     * @param tMhtPlane
     * @return
     */
    @GetMapping("getByCode")
    public LayData getByCode(TMhtPlane tMhtPlane){
        TMhtPlane tMhtPlanes = tMhtPlaneService.getByCode(tMhtPlane);
        return new LayData(tMhtPlanes);
    }

    /**
     * 根据测试计划id检验回访时测试计划是否正确
     */
    @PostMapping("checkPlanId")
    public LayData checkPlanId(String planid){
        boolean status = tMhtPlaneService.checkPlanId(planid);
        return new LayData(status);
    }

}
